#ifndef CVSELAPSEDTIMERHINCLUDED
#define CVSELAPSEDTIMERHINCLUDED
/*
********************************************************************************
Copyright (c) 2001 Center for Visual Science

Module Name: CVSElapsedTimer.h

Abstract: prototype a Win32-oriented high frequency, high resolution timer

History
4/28/02 jeff saunders Added some inline unit conversion, and wait functions
................................................................................
12/11/2001  rmu     created original
12/18/2001  rmu     added Reset(), which allows the timer to be zeroed as needed
********************************************************************************
*/

#include <iostream>

class CVSElapsedTimer
{
public:
	//typedef long long datatype; // this should be equivalent
	typedef __int64 datatype; 
	
	// construct and destructor
	CVSElapsedTimer();
	~CVSElapsedTimer();
	
	// ... Operations
	// ... Retrieve the elapsed time in microseconds.
	datatype ElapsedTime();
	// get elapsed time in different units, returned as double
	double ElapsedTimeSec() { return double(ElapsedTime()/1000000.0); }
	double ElapsedTimeMilliSec() { return double(ElapsedTime()/1000.0); }
	double ElapsedTimeMicroSec() { return double(ElapsedTime()); }

	// ... Call reset to zero the timer.
	void Reset();
	
	// wait functions, like sleep but with more precise timer
	// returns true if waits desired time, false if times out too early
	// (number of cycles of waiting has a max, set at construction)
	bool WaitMilliSec(double wait_time); // hold for specified time in ms
	bool WaitSec(double wait_time) // hold for specified time in sec
		{ return(WaitMilliSec(wait_time*1000.0)); } 
	bool WaitMicroSec(double wait_time) // hold for specified time	in microsec
		{ return(WaitMilliSec(wait_time/1000.0)); } 

	// utility to output some information about the timer params
	void PrintInfo(std::ostream & os); 

private:
	datatype maxNumWaitCycles;
	datatype m_n64TimerFrequency;
	datatype m_n64StartingTime;
};


#endif




